import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:thinking/config/_.dart';
import 'package:thinking/utils/_.dart';

///引导页
class Welcome extends StatefulWidget{


  @override
  _Welcome createState() => _Welcome();

}

class _Welcome extends State<Welcome>{

  late PageController _pageController;
  int _index = 0;

  @override
  void initState() {
    super.initState();
    _pageController=PageController();
  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  PageView welcomePageView(){
    return PageView(
        onPageChanged:(e){
          setState(() {
            _index =e ;
          });
        },
        controller: _pageController,
        children: Config.welComeConfig.asMap()
            .keys.map(
                (e)=> Container(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Container(
                    margin: EdgeInsets.only(top: 10.0),
                    child: ShaderMask(
                      shaderCallback: (Rect bounds) {
                        return LinearGradient(
                          colors: <Color>[  ColorConfig.ThemeColor,
                            ColorConfig.ThemeOtherColor],
                          tileMode: TileMode.mirror,
                        ).createShader(bounds);
                      },
                      blendMode: BlendMode.srcATop,
                      child: Container(
                          child: Text(
                            Config.welComeConfig[e]['topTitle'],
                            style: TextStyle(
                              fontSize: 30.0,
                              color: Colors.grey,
                            ),
                          )
                      ),

                    ),
                  ),
                  ShaderMask(
                    shaderCallback: (Rect bounds) {
                      return LinearGradient(
                        colors: <Color>[  ColorConfig.ThemeColor,
                          ColorConfig.ThemeOtherColor],
                        tileMode: TileMode.mirror,
                      ).createShader(bounds);
                    },
                    blendMode: BlendMode.srcATop,
                    child: Container(
                        child: Text(
                          Config.welComeConfig[e]['topCenter'],
                          style: TextStyle(
                            fontSize: 18.0,
                            color: Colors.grey,
                          ),
                        )
                    ),

                  ),

                  Container(
                      margin: EdgeInsets.only(top: 60.0),
                      child:Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Image(
                            image: AssetImage(
                              Config.welComeConfig[e]['imageUrl'],

                            ),
                            fit:BoxFit.cover,
                            height: Screen.setHeight(175.0),
                          )
                        ],
                      )
                  )

                ],
              ),
            )).toList()


    );
  }

  Row downPageView(){
    return  Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children:
        Config.welComeConfig.asMap().keys.map((e) =>Container(
          margin:EdgeInsets.only(right: 5.0,left: 5.0),
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            color: e == _index?ColorConfig.ThemeColor:Colors.grey,

          ),
          height: Screen.setWidth(8),
          width: Screen.setWidth(8),
        ) ).toList()


    );
  }

  @override
  Widget build(BuildContext context) {



    return Scaffold(
      body: Container(
        color: Colors.white,
        height: Screen.height(context),
        width: Screen.width(context),
        child: Column(
          children: [
            Container(
              margin: EdgeInsets.only(bottom: 10.0,top: 130.0),
              width: Screen.width(context),
              height: Screen.setHeight(357.0),
              child: welcomePageView(),
            ),
            Container(
              margin: EdgeInsets.only(bottom: 10.0,),
              width: Screen.width(context),
              height: Screen.setHeight(50.0),
              child: downPageView() ,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                GestureDetector(
                  onTap: (){
                    goLogin();
                  },
                  child: Container(
                    height: Screen.setHeight(50.0),
                    width: Screen.setWidth(310.0),
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.all(Radius.circular(10.0)),
                        gradient: LinearGradient(
                            colors: <Color>[
                              ColorConfig.ThemeColor,
                              ColorConfig.ThemeOtherColor
                            ]
                        ),
                        boxShadow: [
                          BoxShadow(
                              color:ColorConfig.ThemeColor,
                              offset: Offset(1,1),
                              blurRadius: 2,
                              spreadRadius: 0
                          )
                        ]
                    ),
                    child: Center(
                      child: Text(
                        '登录thinking',
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 18.0,
                            fontWeight: FontWeight.w400,
                            letterSpacing: 1.0
                        ),
                      ),
                    ),
                  ),
                )
                ],
            )
          ],
        ),
      ),
    );
  }




///前往登录页
  void goLogin(){
     Modular.to.pushReplacementNamed('/signUp');

  }
}

